package com.foo.ui_demo_widge;

import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.DialogFragment;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;

import com.example.ui_demo_widget1.dialog.ListDialogFragment;
import com.example.ui_demo_widget1.dialog.LoginDialogFragment;
import com.example.ui_demo_widget1.dialog.MultiChoiceDialogFragment;
import com.example.ui_demo_widget1.dialog.SingledialogFragment;
import com.example.ui_demo_widget1.dialog.TipDialogFragment;

import java.util.ArrayList;
import java.util.List;

public class DialogDemoActivity extends AppCompatActivity implements View.OnClickListener {
public int checkItem;
public ArrayList<Integer> selectedItem=new ArrayList<Integer>();
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_dialog_demo);
        findViewById(R.id.btn_tip).setOnClickListener(this);
        findViewById(R.id.btn_list).setOnClickListener(this);
        findViewById(R.id.btn_single).setOnClickListener(this);
        findViewById(R.id.btn_multi_choice).setOnClickListener(this);
        findViewById(R.id.btn_login_dialog).setOnClickListener(this);
    }

    @Override
    public void onClick(View view) {
        int id=view.getId();
        DialogFragment fragment=null;
        String tag=null;
        if (R.id.btn_tip==id){
            tag="TipDialogFragment";
            fragment=new TipDialogFragment();
        }
        if (R.id.btn_list==id){
            tag="ListDialogFragment";
             fragment=new ListDialogFragment();
            ((ListDialogFragment)fragment).setOnsendMsgListener(new ListDialogFragment.OnsendMsgListener() {
                @Override
                public void sendMsg(String msg) {
                    Button btn = findViewById(R.id.btn_list);
                    btn.setText(msg);
                }
            });
        }
        if (R.id.btn_single==id){
            tag="SingleDialogFragment";
            fragment=new SingledialogFragment();
        }
        if (R.id.btn_multi_choice==id){
            tag="MultiChoiceDialogFragment";
            fragment=new MultiChoiceDialogFragment();
        }
        if (R.id.btn_login_dialog==id){
            tag="LoginDialogFragment";
            fragment=new LoginDialogFragment();
        }
        if (null!=fragment){
            fragment.show(getSupportFragmentManager(),tag);
        }
    }
}